package cn.hfatec.shms.web.xm.xmCgmj.service;

import java.util.Date;
import java.util.List;
import java.util.HashMap;


import cn.hfatec.shms.system.user.model.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.xm.xmCgmj.model.XmCgmj;
import cn.hfatec.shms.web.xm.xmCgmj.dao.XmCgmjDao;
import cn.hfatec.shms.web.xm.xmCgmj.model.XmCgmjParams;

import javax.annotation.Resource;


/**
 * @author hfatec
 * @version 1.0
 *          <p/>
 *          the JAVA code is generate by middlegen
 */
@Service("XmCgmjService")
public class XmCgmjService {

    public static final String BEAN_ID = "XmCgmjService";

    //注入Dao层
    @Resource(name = "XmCgmjDao")
    private XmCgmjDao xmCgmjDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     * 查询数据
     *
     * @param xmCgmjParams
     * @param page
     */
    @Transactional
    public Table queryXmCgmjTable(XmCgmjParams xmCgmjParams, Page page) {

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", xmCgmjParams);
        return baseDao.queryTableByPage("queryXmCgmj", params, page);
    }
    /**
     * 查询数据
     *
     * @param xmCgmjParams
     *
     */
    @Transactional
    public XmCgmj XmCgmjHj(XmCgmjParams xmCgmjParams) {
     return  xmCgmjDao.queryXmCgmjHj(xmCgmjParams);
    }

    /**
     * 插入数据
     *
     * @param xmCgmj
     */
    @Transactional
    public void saveXmCgmj(String[] ids, String[] DTypes, String[] XTypes, String[] fieldAs, String[] fieldBs, String[] fieldCs, String[] fieldDs, String[] fieldEs, XmCgmj xmCgmj, User user) {
        if (xmCgmj.getId() != null) {
            XmCgmj result = getXmCgmj(xmCgmj.getId());
            if (result != null) {
                if (DTypes != null) {
                    for (int i = 0; i < DTypes.length; i++) {
                        XmCgmj xmCgmjIns=new XmCgmj();

                        xmCgmjIns.setUserName(xmCgmj.getUserName());
                        xmCgmjIns.setFieldK(xmCgmj.getFieldK());
                        xmCgmjIns.setBillTime(xmCgmj.getBillTime());
                        if (!DTypes[i].equals(""))
                            xmCgmjIns.setDType(DTypes[i]);
                        if(!XTypes[i].equals(""))
                            xmCgmjIns.setXType(XTypes[i]);
                        if(!fieldAs[i].equals(""))
                            xmCgmjIns.setFieldA(fieldAs[i]);
                        if(!fieldBs[i].equals(""))
                            xmCgmjIns.setFieldB(fieldBs[i]);
                        if(!fieldCs[i].equals(""))
                            xmCgmjIns.setFieldC(fieldCs[i]);
                        if(!fieldDs[i].equals(""))
                            xmCgmjIns.setFieldD(fieldDs[i]);
                        if(!fieldEs[i].equals(""))
                            xmCgmjIns.setFieldE(fieldEs[i]);
                        if (ids[i] != "") {

                            xmCgmjIns.setId(Integer.parseInt(ids[i]));
                            xmCgmjDao.update(xmCgmjIns);
                        } else {

                            xmCgmjIns.setId(null);
                            xmCgmjDao.insert(xmCgmjIns);
                        }

                    }}}



        } else {
            if (DTypes != null) {
                for (int i = 0; i < DTypes.length; i++) {
                    XmCgmj xmCgmjIns=new XmCgmj();
                    xmCgmjIns.setUserName(xmCgmj.getUserName());
                    xmCgmjIns.setFieldK(xmCgmj.getFieldK());
                    xmCgmjIns.setBillTime(xmCgmj.getBillTime());
                    if (!DTypes[i].equals(""))
                        xmCgmjIns.setDType(DTypes[i]);
                    if(!XTypes[i].equals(""))
                        xmCgmjIns.setXType(XTypes[i]);
                    if(!fieldAs[i].equals(""))
                        xmCgmjIns.setFieldA(fieldAs[i]);
                    if(!fieldBs[i].equals(""))
                        xmCgmjIns.setFieldB(fieldBs[i]);
                    if(!fieldCs[i].equals(""))
                        xmCgmjIns.setFieldC(fieldCs[i]);
                    if(!fieldDs[i].equals(""))
                        xmCgmjIns.setFieldD(fieldDs[i]);
                    if(!fieldEs[i].equals(""))
                        xmCgmjIns.setFieldE(fieldEs[i]);
                    xmCgmjIns.setCreatName(user.getLoginName());
                    xmCgmjIns.setCreatTime(new Date().toString());
                    xmCgmjDao.insert(xmCgmjIns);
            }
        }
    }

}

    /**
     * 删除数据
     *
     * @param id
     */
    @Transactional
    public void deleteXmCgmj(Integer id) {

        xmCgmjDao.delete(id);
    }
    /**
     * 删除数据
     *
     * @param billTime
     */
    @Transactional
    public void deleteXmCgmjTime(String billTime) {

        xmCgmjDao.deleteTime(billTime);
    }


    /**
     * 删除数据
     *
     * @param xmCgmjList
     */
    @Transactional
    public void deleteXmCgmjBatch(List<String> xmCgmjList) {
        for (String billTime : xmCgmjList) {
            deleteXmCgmjTime(billTime);

//            deleteXmCgmj(Integer.valueOf(id));
        }
    }

    /**
     * 根据ID获取数据
     *
     * @param id
     */
    @Transactional
    public XmCgmj getXmCgmj(Integer id) {

        return xmCgmjDao.getXmCgmjById(id);
    }




    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmA() {

        return xmCgmjDao.getXmCgmjXmA();
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmB() {

        return xmCgmjDao.getXmCgmjXmB();
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmC() {

        return xmCgmjDao.getXmCgmjXmC();
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmD() {

        return xmCgmjDao.getXmCgmjXmD();
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmE() {
        return xmCgmjDao.getXmCgmjXmE();
    }





    /**
     * 根据billTime获取数据
     *
     * @param billTime
     */
    @Transactional
    public XmCgmj XmCgmjTime(String  billTime) {
        return xmCgmjDao.getXmCgmjTime(billTime);
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmAedi(String  billTime) {

        return xmCgmjDao.getXmCgmjXmAedi(billTime);
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmBedi(String  billTime) {

        return xmCgmjDao.getXmCgmjXmBedi(billTime);
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmCedi(String  billTime) {

        return xmCgmjDao.getXmCgmjXmCedi(billTime);
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmDedi(String  billTime) {

        return xmCgmjDao.getXmCgmjXmDedi(billTime);
    }
    /**
     * 健管
     */
    @Transactional
    public List XmCgmjXmEedi(String  billTime) {
        return xmCgmjDao.getXmCgmjXmEedi(billTime);
    }
}